﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda INodeFilter</summary>
    public class INodeFilter : IDisposable
    {
        /// <summary>
        /// Pre test node su pouzite properties objektu INode - Name, Attributes, Size, DCreate, DLastModify, DLastAccess
        /// </summary>

        public const int COMPARE_MODE_E = 0;
        public const int COMPARE_MODE_NE = 1;
        public const int COMPARE_MODE_L = 2;
        public const int COMPARE_MODE_LE = 3;
        public const int COMPARE_MODE_G = 4;
        public const int COMPARE_MODE_GE = 5;

        public const int SIZE_MODE_B = 0;
        public const int SIZE_MODE_KB = 1;
        public const int SIZE_MODE_MB = 2;
        public const int SIZE_MODE_GB = 3;

        public const int AGE_MODE_MINUTE = 0;
        public const int AGE_MODE_HOUR = 1;
        public const int AGE_MODE_DAY = 2;
        public const int AGE_MODE_MONTH = 3;
        public const int AGE_MODE_YEAR = 4;

        public bool UseName; // Priznaky pouzitia
        public bool UseAttributes;
        public bool UseSize;
        public bool UseDCreate;
        public bool UseDModify;
        public bool UseDLastAccess;
        public bool UseAge;

        public string FilterValue_Name; // Hodnoty filtrov

        public byte FilterValue_Attr_Archive;
        public byte FilterValue_Attr_Compressed;
        public byte FilterValue_Attr_Directory;
        public byte FilterValue_Attr_Encrypted;
        public byte FilterValue_Attr_Hidden;
        public byte FilterValue_Attr_Readonly;
        public byte FilterValue_Attr_System;

        public int FilterValue_SizeMode;
        public long FilterValue_Size;
        public int FilterValue_SizeCompareMode;

        public int FilterValue_Age;
        public int FilterValue_AgeMode;

        public DateTime FilterValue_DCreateMin, FilterValue_DCreateMax;
        public DateTime FilterValue_DModifyMin, FilterValue_DModifyMax;
        public DateTime FilterValue_DLastAccessMin, FilterValue_DLastAccessMax;

        protected bool FValidSize; // Pomocne premenne
        protected bool FValidAge;
        protected bool FValidName;
        protected long FRealSize;
        protected DateTime FBoundDate;
        protected string[] FWildcards;

        /// <summary>Otestovanie hodnoty atributu</summary>
        /// <param name="pAttrValue">hodnota testovaneho atributu</param>
        /// <param name="pAttrs">vsetky atributy</param>
        /// <param name="pAttrMask">maska atributu</param>
        /// <returns>true / false</returns>
        protected bool TestAttrValue(byte pAttrValue, uint pAttrs, uint pAttrMask)
        {
            if (pAttrValue == ICore.TS_NONE) return true;
            if (pAttrValue == ICore.TS_TRUE) return (pAttrs & pAttrMask) != 0;
            return (pAttrs & pAttrMask) == 0;
        }
        /// <summary>Otestovanie datumu</summary>
        /// <param name="pApply">priznak pouzitia</param>
        /// <param name="pValue">hodnota</param>
        /// <param name="pMin">minimum</param>
        /// <param name="pMax">maximum</param>
        /// <returns></returns>
        protected bool TestDate(bool pApply, DateTime pValue, DateTime pMin, DateTime pMax)
        {
            if (!pApply) return true; // Nepouzit?
            if ((pMin != DateTime.MinValue) && (pValue < pMin)) return false;// Pouzit minimum?
            if ((pMax != DateTime.MinValue) && (pValue >= pMax)) return false;// Pouzit maximum?
            return true; // Preslo
        }

        /// <summary>Property: UseFilter</summary>
        public bool UseFilter
        {
            get
            {
                if (UseName) return true;
                if (UseAttributes) return true;
                if (UseSize) return true;
                if (UseDCreate) return true;
                if (UseDModify) return true;
                if (UseDLastAccess) return true;
                if (UseAge) return true;
                return false;
            }
        }
        /// <summary>Property: DisplayValue</summary>
        public string DisplayValue
        {
            get
            {
                string DV_Name = UseName ? lang.FORM_EDIT_FILTER_TEXT_12_2 : "";
                string DV_Attr = UseAttributes ? lang.FORM_EDIT_FILTER_TEXT_12_3 : "";
                string DV_Size = UseSize ? lang.FORM_EDIT_FILTER_TEXT_12_4 : "";
                string DV_Age = UseAge ? lang.FORM_EDIT_FILTER_TEXT_12_5 : "";
                string DV_DCreate = UseDCreate ? lang.FORM_EDIT_FILTER_TEXT_12_6 : "";
                string DV_DModify = UseDModify ? lang.FORM_EDIT_FILTER_TEXT_12_7 : "";
                string DV_DLastAccess = UseDLastAccess ? lang.FORM_EDIT_FILTER_TEXT_12_8 : "";

                string S = string.Format("{0}  {1}  {2}  {3}  {4}  {5}  {6}", DV_Name, DV_Attr, DV_Size, DV_Age, DV_DCreate, DV_DModify, DV_DLastAccess);
                S = S.Trim().Replace("  ", ", ");
                return S == "" ? "" : string.Format(lang.FORM_EDIT_FILTER_TEXT_12_1, S);
            }
        }

        /// <summary>Konstruktor</summary>
        public INodeFilter()
        {
            Init();
        }
        /// <summary>Destruktor</summary>
        public void Dispose()
        {
        }

        /// <summary>Inicializacia</summary>
        public void Init()
        {
            UseName = false;
            UseAttributes = false;
            UseSize = false;
            UseDCreate = false;
            UseDModify = false;
            UseDLastAccess = false;
            UseAge = false;
            FilterValue_Name = "";
            FilterValue_Attr_Archive = ICore.TS_NONE;
            FilterValue_Attr_Compressed = ICore.TS_NONE;
            FilterValue_Attr_Directory = ICore.TS_NONE;
            FilterValue_Attr_Encrypted = ICore.TS_NONE;
            FilterValue_Attr_Hidden = ICore.TS_NONE;
            FilterValue_Attr_Readonly = ICore.TS_NONE;
            FilterValue_Attr_System = ICore.TS_NONE;
            FilterValue_SizeMode = SIZE_MODE_B;
            FilterValue_Size = 0;
            FilterValue_SizeCompareMode = COMPARE_MODE_E;
            FilterValue_Age = 0;
            FilterValue_AgeMode = AGE_MODE_DAY;
            FilterValue_DCreateMin = DateTime.MinValue; FilterValue_DCreateMax = DateTime.MinValue;
            FilterValue_DModifyMin = DateTime.MinValue; FilterValue_DModifyMax = DateTime.MinValue;
            FilterValue_DLastAccessMin = DateTime.MinValue; FilterValue_DLastAccessMax = DateTime.MinValue;
            FValidSize = false; FValidAge = false; FValidName = false;
            FWildcards = null;
        }
        /// <summary>Skopirovanie obsahu objektu</summary>
        /// <param name="pValue">objekt pre skopirovanie</param>
        public void Assign(INodeFilter pValue)
        {
            UseName = pValue.UseName;
            UseAttributes = pValue.UseAttributes;
            UseSize = pValue.UseSize;
            UseDCreate = pValue.UseDCreate;
            UseDModify = pValue.UseDModify;
            UseDLastAccess = pValue.UseDLastAccess;
            UseAge = pValue.UseAge;
            FilterValue_Name = pValue.FilterValue_Name;
            FilterValue_Attr_Archive = pValue.FilterValue_Attr_Archive;
            FilterValue_Attr_Compressed = pValue.FilterValue_Attr_Compressed;
            FilterValue_Attr_Directory = pValue.FilterValue_Attr_Directory;
            FilterValue_Attr_Encrypted = pValue.FilterValue_Attr_Encrypted;
            FilterValue_Attr_Hidden = pValue.FilterValue_Attr_Hidden;
            FilterValue_Attr_Readonly = pValue.FilterValue_Attr_Readonly;
            FilterValue_Attr_System = pValue.FilterValue_Attr_System;
            FilterValue_SizeMode = pValue.FilterValue_SizeMode;
            FilterValue_Size = pValue.FilterValue_Size;
            FilterValue_SizeCompareMode = pValue.FilterValue_SizeCompareMode;
            FilterValue_Age = pValue.FilterValue_Age;
            FilterValue_AgeMode = pValue.FilterValue_AgeMode;
            FilterValue_DCreateMin = pValue.FilterValue_DCreateMin;
            FilterValue_DCreateMax = pValue.FilterValue_DCreateMax;
            FilterValue_DModifyMin = pValue.FilterValue_DModifyMin;
            FilterValue_DModifyMax = pValue.FilterValue_DModifyMax;
            FilterValue_DLastAccessMin = pValue.FilterValue_DLastAccessMin;
            FilterValue_DLastAccessMax = pValue.FilterValue_DLastAccessMax;
        }
        /// <summary>Serializacia obsahu</summary>
        /// <param name="pEncode">priznak zakodovania vysledku</param>
        public string Serialize()
        {
            try
            {
                using (System.IO.MemoryStream MS = new System.IO.MemoryStream())
                {
                    using (System.IO.BinaryWriter W = new System.IO.BinaryWriter(MS))
                    {
                        W.Write(UseName);
                        W.Write(UseAttributes);
                        W.Write(UseSize);
                        W.Write(UseDCreate);
                        W.Write(UseDModify);
                        W.Write(UseDLastAccess);
                        W.Write(UseAge);
                        W.Write(FilterValue_Name);
                        W.Write(FilterValue_Attr_Archive);
                        W.Write(FilterValue_Attr_Compressed);
                        W.Write(FilterValue_Attr_Directory);
                        W.Write(FilterValue_Attr_Encrypted);
                        W.Write(FilterValue_Attr_Hidden);
                        W.Write(FilterValue_Attr_Readonly);
                        W.Write(FilterValue_Attr_System);
                        W.Write(FilterValue_SizeMode);
                        W.Write(FilterValue_Size);
                        W.Write(FilterValue_SizeCompareMode);
                        W.Write(FilterValue_Age);
                        W.Write(FilterValue_AgeMode);
                        W.Write(FilterValue_DCreateMin.Ticks);
                        W.Write(FilterValue_DCreateMax.Ticks);
                        W.Write(FilterValue_DModifyMin.Ticks);
                        W.Write(FilterValue_DModifyMax.Ticks);
                        W.Write(FilterValue_DLastAccessMin.Ticks);
                        W.Write(FilterValue_DLastAccessMax.Ticks);
                    }
                    return ICore.Base64EncodeData(MS.ToArray());
                }
            }
            catch
            {
                return ""; // Chyba
            }
        }
        /// <summary>Deserializacia obsahu</summary>
        /// <param name="pData">serializovany obsah</param>
        public void Deserialize(string pData)
        {
            try
            {
                Init(); // Inicializacia

                byte[] RawData = ICore.Base64DecodeData(pData); // Dekodujem vstup
                if (RawData == null) return; // Prazdny vstup?

                using (System.IO.MemoryStream MS = new System.IO.MemoryStream(RawData))
                {
                    using (System.IO.BinaryReader R = new System.IO.BinaryReader(MS))
                    {
                        UseName = R.ReadBoolean();
                        UseAttributes = R.ReadBoolean();
                        UseSize = R.ReadBoolean();
                        UseDCreate = R.ReadBoolean();
                        UseDModify = R.ReadBoolean();
                        UseDLastAccess = R.ReadBoolean();
                        UseAge = R.ReadBoolean();
                        FilterValue_Name = R.ReadString();
                        FilterValue_Attr_Archive = R.ReadByte();
                        FilterValue_Attr_Compressed = R.ReadByte();
                        FilterValue_Attr_Directory = R.ReadByte();
                        FilterValue_Attr_Encrypted = R.ReadByte();
                        FilterValue_Attr_Hidden = R.ReadByte();
                        FilterValue_Attr_Readonly = R.ReadByte();
                        FilterValue_Attr_System = R.ReadByte();
                        FilterValue_SizeMode = R.ReadInt32();
                        FilterValue_Size = R.ReadInt64();
                        FilterValue_SizeCompareMode = R.ReadInt32();
                        FilterValue_Age = R.ReadInt32();
                        FilterValue_AgeMode = R.ReadInt32();
                        FilterValue_DCreateMin = new DateTime(R.ReadInt64());
                        FilterValue_DCreateMax = new DateTime(R.ReadInt64());
                        FilterValue_DModifyMin = new DateTime(R.ReadInt64());
                        FilterValue_DModifyMax = new DateTime(R.ReadInt64());
                        FilterValue_DLastAccessMin = new DateTime(R.ReadInt64());
                        FilterValue_DLastAccessMax = new DateTime(R.ReadInt64());
                    }
                }
            }
            catch
            {
                Init(); // Chyba
            }
        }
        /// <summary>Editacia objektu pomocou formulara</summary>
        /// <param name="pCaption">nadpis okna</param>
        /// <returns>true / false</returns>
        public bool EditWithForm(string pCaption)
        {
            using (IFileExplorerForm_EditNodeFilter F = new IFileExplorerForm_EditNodeFilter()) // Vytvorim form
            {
                F.Text = pCaption; F.Value.Assign(this); // Ulozim hodnoty
                bool B = F.ShowDialog() == System.Windows.Forms.DialogResult.OK; // Zobrazim
                if (B) Assign(F.Value);
                return B;
            }
        }

        /// <summary>Otestovanie podmienok na objekte node</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode(INode pNode)
        {
            if (!TestNode_Attributes(pNode)) return false;
            if (!TestNode_Size(pNode)) return false;
            if (!TestNode_Age(pNode)) return false;
            if (!TestNode_Dates(pNode)) return false;
            if (!TestNode_Name(pNode)) return false;
            return true; // Preslo
        }
        /// <summary>Otestovanie podmienok na objekte node - nazov</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode_Name(INode pNode)
        {
            if (!UseName) return true; // Nepouzit nazov?
            if (!FValidName)
            {
                try
                {
                    FValidName = true;
                    FWildcards = FilterValue_Name.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < FWildcards.Length; i++)
                    {
                        if ((FWildcards[i].IndexOf('*') == -1) && (FWildcards[i].IndexOf('?') == -1))  FWildcards[i] = "*" + FWildcards[i] + "*";
                        FWildcards[i] = FWildcards[i].ToLower(); // Prevediem na male pismena
                    }
                }
                catch
                {
                    FWildcards = null;
                }
            }
            if (FWildcards == null) return true;
            foreach (string S in FWildcards)
            {
                if (WildcardMatch(pNode.Name.ToLower(), S)) return true;
            }
            return false;
        }
        /// <summary>Otestovanie podmienok na objekte node - atributy</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode_Attributes(INode pNode)
        {
            if (!UseAttributes) return true; // Nepouzit?

            uint Attr = pNode.Attributes; // Ziskam atributy
            if (!TestAttrValue(FilterValue_Attr_Archive, Attr, IWin32.FILE_ATTRIBUTE_ARCHIVE)) return false; // Testujem jednotlive atributy
            if (!TestAttrValue(FilterValue_Attr_Compressed, Attr, IWin32.FILE_ATTRIBUTE_COMPRESSED)) return false;
            if (!TestAttrValue(FilterValue_Attr_Directory, Attr, IWin32.FILE_ATTRIBUTE_DIRECTORY)) return false;
            if (!TestAttrValue(FilterValue_Attr_Encrypted, Attr, IWin32.FILE_ATTRIBUTE_ENCRYPTED)) return false;
            if (!TestAttrValue(FilterValue_Attr_Hidden, Attr, IWin32.FILE_ATTRIBUTE_HIDDEN)) return false;
            if (!TestAttrValue(FilterValue_Attr_Readonly, Attr, IWin32.FILE_ATTRIBUTE_READONLY)) return false;
            if (!TestAttrValue(FilterValue_Attr_System, Attr, IWin32.FILE_ATTRIBUTE_SYSTEM)) return false;

            return true;
        }
        /// <summary>Otestovanie podmienok na objekte node - velkost</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode_Size(INode pNode)
        {
            if (!UseSize) return true; // Nepouzit velkost?

            if (!FValidSize)
            {
                FRealSize = FilterValue_Size; // Urcim skutocnu velkost
                switch (FilterValue_SizeMode)
                {
                    case SIZE_MODE_KB: FRealSize *= 1024; break;
                    case SIZE_MODE_MB: FRealSize *= 1024 * 1204; break;
                    case SIZE_MODE_GB: FRealSize *= 1024 * 1204 * 1204; break;
                }
            }

            switch (FilterValue_SizeCompareMode) // Podla modu porovnania
            {
                case COMPARE_MODE_NE: return FRealSize != pNode.Size;
                case COMPARE_MODE_L: return FRealSize > pNode.Size;
                case COMPARE_MODE_LE: return FRealSize >= pNode.Size;
                case COMPARE_MODE_G: return FRealSize < pNode.Size;
                case COMPARE_MODE_GE: return FRealSize <= pNode.Size;
                default: return FRealSize == pNode.Size;
            }
        }
        /// <summary>Otestovanie podmienok na objekte node - vek</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode_Age(INode pNode)
        {
            if (!UseAge) return true; // Nepouzit?

            if (!FValidAge)
            {
                FBoundDate = DateTime.Now;
                switch (FilterValue_AgeMode)
                {
                    case AGE_MODE_MINUTE: FBoundDate = FBoundDate.AddMinutes(-FilterValue_Age); break;
                    case AGE_MODE_HOUR: FBoundDate = FBoundDate.AddHours(-FilterValue_Age); break;
                    case AGE_MODE_DAY: FBoundDate = FBoundDate.AddDays(-FilterValue_Age); break;
                    case AGE_MODE_MONTH: FBoundDate = FBoundDate.AddMonths(-FilterValue_Age); break;
                    default: FBoundDate = FBoundDate.AddYears(-FilterValue_Age); break;
                }
            }

            return FBoundDate <= pNode.DCreate;
        }
        /// <summary>Otestovanie podmienok na objekte node - datumy</summary>
        /// <param name="pNode">node</param>
        /// <returns>true / false</returns>
        public bool TestNode_Dates(INode pNode)
        {
            if (!TestDate(UseDCreate, pNode.DCreate, FilterValue_DCreateMin, FilterValue_DCreateMax)) return false;
            if (!TestDate(UseDModify, pNode.DLastModify, FilterValue_DModifyMin, FilterValue_DModifyMax)) return false;
            if (!TestDate(UseDLastAccess, pNode.DLastAccess, FilterValue_DLastAccessMin, FilterValue_DLastAccessMax)) return false;
            return true; // Preslo
        }

        /// <summary>Wildcard porovnanie</summary>
        /// <param name="strCompare">maska</param>
        /// <param name="strWild">testovaci retazec</param>
        /// <returns>true / false</returns>
        public static bool WildcardMatch(string strCompare, string strWild)
        {
            // Lengths of strings
            int iWildLen = strWild.Length;
            int iCompareLen = strCompare.Length;

            // Used to save position when '*' found in strWild
            // Initialized to invalid values
            int iWildMatched = iWildLen;
            int iCompareBase = iCompareLen;

            int iWild = 0;
            int iCompare = 0;

            // Match until first wildcard '*'
            while (iCompare < iCompareLen && (iWild >= iWildLen || strWild[iWild] != '*'))
            {
                if (iWild >= iWildLen || (strWild[iWild] != strCompare[iCompare] && strWild[iWild] != '?'))
                    return false;

                iWild++;
                iCompare++;
            }

            // Process wildcard
            while (iCompare < iCompareLen)
            {
                if (iWild < iWildLen)
                {
                    if (strWild[iWild] == '*')
                    {
                        iWild++;

                        if (iWild == iWildLen)
                            return true;

                        iWildMatched = iWild;
                        iCompareBase = iCompare + 1;

                        continue;
                    }

                    if (strWild[iWild] == strCompare[iCompare] || strWild[iWild] == '?')
                    {
                        iWild++;
                        iCompare++;

                        continue;
                    }
                }

                iWild = iWildMatched;
                iCompare = iCompareBase++;
            }

            while (iWild < iWildLen && strWild[iWild] == '*')
                iWild++;

            if (iWild < iWildLen)
                return false;

            return true;
        }
    }

    /// <summary>Trieda INodeFilters</summary>
    public class INodeFilters : IDisposable
    {
        public const int LOG_OPERATOR_OR = 0;
        public const int LOG_OPERATOR_AND = 1;

        public const int PREDDEFINED_ID_ALL = 0;
        public const int PREDDEFINED_ID_DIR = 1;
        public const int PREDDEFINED_ID_TEXT = 2;
        public const int PREDDEFINED_ID_DATA = 3;
        public const int PREDDEFINED_ID_AUDIO = 4;
        public const int PREDDEFINED_ID_VIDEO = 5;
        public const int PREDDEFINED_ID_3D_IMAGE = 6;
        public const int PREDDEFINED_ID_RASTER_IMAGE = 7;
        public const int PREDDEFINED_ID_VECTOR_IMAGE = 8;
        public const int PREDDEFINED_ID_PAGE_LAYOUT = 9;
        public const int PREDDEFINED_ID_SPREAD_SHEET = 10;
        public const int PREDDEFINED_ID_DATABASE = 11;
        public const int PREDDEFINED_ID_EXE = 12;
        public const int PREDDEFINED_ID_GAME = 13;
        public const int PREDDEFINED_ID_CAD = 14;
        public const int PREDDEFINED_ID_GIS = 15;
        public const int PREDDEFINED_ID_WEB = 16;
        public const int PREDDEFINED_ID_PLUGIN = 17;
        public const int PREDDEFINED_ID_FONT = 18;
        public const int PREDDEFINED_ID_SYSTEM = 19;
        public const int PREDDEFINED_ID_SETTINGS = 20;
        public const int PREDDEFINED_ID_ENCODED = 21;
        public const int PREDDEFINED_ID_COMPRESSED = 22;
        public const int PREDDEFINED_ID_DISK_IMAGE = 23;
        public const int PREDDEFINED_ID_DEVEL = 24;
        public const int PREDDEFINED_ID_BACKUP = 25;

        public int LogOperator; // Logicka spojka medzi filtrami

        protected System.Collections.Generic.List<INodeFilter> FItems; // Zoznam

        /// <summary>Property: Count</summary>
        public int Count
        {
            get
            {
                return FItems.Count;
            }
        }
        /// <summary>Property: []</summary>
        /// <param name="pIndex">pozicia</param>
        /// <returns>object alebo null</returns>
        public INodeFilter this[int pIndex]
        {
            get
            {
                return ((pIndex < 0) || (pIndex >= FItems.Count)) ? null : FItems[pIndex];
            }
        }

        /// <summary>Konstruktor</summary>
        public INodeFilters()
        {
            FItems = new System.Collections.Generic.List<INodeFilter>(); // Inicializacia
            LogOperator = LOG_OPERATOR_AND;
        }
        /// <summary>Dispose metoda</summary>
        public void Dispose()
        {
            if (FItems != null)
            {
                Clear();
                FItems = null;
            }
        }

        /// <summary>Vymazanie zoznamu</summary>
        public void Clear()
        {
            for (int i = 0; i < FItems.Count; i++) // Vymazem vsetky objekty
            {
                FItems[i].Dispose();
            }
            FItems.Clear();
            LogOperator = LOG_OPERATOR_AND;
        }
        /// <summary>Skopirovanie obsahu objektu</summary>
        /// <param name="pValue">objekt pre skopirovanie</param>
        public void Assign(INodeFilters pValue)
        {
            Clear(); // Vymazem aktualny obsah
            for (int i = 0; i < pValue.FItems.Count; i++)
            {
                INodeFilter F = new INodeFilter(); // Vytvorim filter
                F.Assign(pValue.FItems[i]); // Skpirujem
                FItems.Add(F); // Zaradim do zoznamu
            }
            LogOperator = pValue.LogOperator;
        }
        /// <summary>Zaradenie filtra do zoznamu</summary>
        /// <param name="pValue">filter</param>
        /// <returns>pozicia zaradenia</returns>
        public int AddFilter(INodeFilter pValue)
        {
            FItems.Add(pValue);
            return FItems.Count - 1;
        }
        /// <summary>Vymazanie filtra</summary>
        /// <param name="pIndex">pozicia</param>
        public void DeleteFilter(int pIndex)
        {
            if ((pIndex < 0) || (pIndex >= FItems.Count)) return; // Mimo rozsah
            FItems[pIndex].Dispose(); FItems.RemoveAt(pIndex); // Zrusim objekt a vyradim ho zo zoznamu
        }

        /// <summary>Serializacia obsahu</summary>
        /// <returns>serializovany obsah</returns>
        public string Serialize()
        {
            System.Collections.Generic.List<string> L = new System.Collections.Generic.List<string>(); // Vytvorim zoznam
            L.Add(LogOperator.ToString()); // Ulozim log. operaciu
            foreach (INodeFilter F in FItems) L.Add(F.Serialize()); // Serializujem kazdy filter
            return ICore.Base64Encode(ICore.StringList2String(L, ";")); // Serilizujem zoznam a zakodujem
        }
        /// <summary>Deserializacia obsahu</summary>
        /// <param name="pData">serializovany obsah</param>
        public void Deserialize(string pData)
        {
            try
            {
                Clear(); // Zmazem aktualny obsah
                System.Collections.Generic.List<string> L = ICore.String2StringList(ICore.Base64Decode(pData), ";");
                if ((L == null) || (L.Count == 0)) return; // Nic na extrakciu?

                LogOperator = ICore.ToInt(L[0]);
                for (int i = 1; i < L.Count; i++)  // Kazdy zaznam...
                {
                    INodeFilter F = new INodeFilter();
                    F.Deserialize(L[i]);
                    FItems.Add(F);
                }
            }
            catch
            {
                Clear(); // Chyba
            }
        }

        /// <summary>Editacia objektu pomocou formulara</summary>
        /// <param name="pCaption">nadpis okna</param>
        /// <returns>true / false</returns>
        public bool EditWithForm(string pCaption)
        {
            using (IFileExplorerForm_EditNodeFilters F = new IFileExplorerForm_EditNodeFilters()) // Vytvorim form
            {
                F.Text = pCaption; F.Value.Assign(this); // Ulozim hodnoty
                bool B = F.ShowDialog() == System.Windows.Forms.DialogResult.OK; // Zobrazim
                if (B) Assign(F.Value);
                return B;
            }
        }

        /// <summary>Otestovanie node</summary>
        /// <param name="pNode">objekt node</param>
        /// <returns>true / false</returns>
        public bool TestNode(INode pNode)
        {
            if (FItems == null) return true;
            if (FItems.Count == 0) return true; // Ziaden filter?

            if (LogOperator == LOG_OPERATOR_AND) // AND logicka spojka?
            {
                for (int i = 0; i < FItems.Count; i++) // Prejdem vsetky filtre
                {
                    if (!FItems[i].TestNode(pNode)) return false;
                }
                return true;
            }
            else // OR spojka
            {
                for (int i = 0; i < FItems.Count; i++) // Prejdem vsetky filtre
                {
                    if (FItems[i].TestNode(pNode)) return true;
                }
                return false;
            }
        }

        /// <summary>Nacitanie preddefinovaneho filtra</summary>
        /// <param name="pID">ID</param>
        public void LoadPreddefined(int pID)
        {
            Clear(); // Inicializujem

            switch (pID)
            {
                case PREDDEFINED_ID_TEXT:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.doc;*.docx;*.log;*.msg;*.odt;*.pages;*.rtf;*.tex;*.txt;*.wpd;*.wps"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_DATA:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.csv;*.dat;*.db;*.dbf;*.efx;*.epub;*.gbr;*.ged;*.ibooks;*.key;*.pps;*.ppt;*.pptx;*.cdf;*.tar;*.vcf;*.xml"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_AUDIO:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.aif;*.iff;*.m3u;*.m4a;*.mid;*.mp3;*.mpa;*.ra;*.wav;*.wma"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_VIDEO:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.3g2;*.3gp;*.asf;*.asx;*.avi;*.flv;*.mov;*.mp4;*.mpg;*.rm;*.srt;*.swf;*.vob;*.wmv;*.sub"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_3D_IMAGE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.3dm;*.max;*.obj"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_RASTER_IMAGE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.bmp;*.dds;*.gif;*.jpg;*.jpeg;*.png;*.psd;*.pspimage;*.tga;*.thm;*.tif;*.yuv"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_VECTOR_IMAGE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.ai;*.eps;*.ps;*.svg"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_PAGE_LAYOUT:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.indd;*.pct;*.pdf;*.xps;*.ps"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_SPREAD_SHEET:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.xlr;*.xls;*.xlsx"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_DATABASE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.accdb;*.db;*.dbf;*.mdb;*.pdb;*.sql"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_EXE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.app;*.bat;*.cgi;*.com;*.exe;*.gadget;*.jar;*.pif;*.vb;*.wsf;*.dll"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_GAME:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.dem;*.gam;*.nes;*.rom;*.sav"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_CAD:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.dwg;*.dxf"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_GIS:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.gpx;*.kml"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_WEB:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.asp;*.aspx;*.cer;*.cfm;*.csr;*.css;*.htm;*.html;*.js;*.jsp;*.php;*.rss;*.xhtml;*.xml"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_PLUGIN:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.8bi;*.plugin;*.xll"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_FONT:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.fnt;*.fon;*.otf;*.ttf"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_SYSTEM:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.cab;*.cpl;*.cur;*.dll;*.dmp;*.drv;*.lnk;*.icns;*.ico;*.sys"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_SETTINGS:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.cfg;*.ini;*.keychain;*.prf"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_ENCODED:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.hqx;*.mim;*.uue"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_COMPRESSED:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.cab;*.7z;*.deb;*.gz;*.pkg;*.rar;*.rmp;*.sit;*.sitx;*.zip;*.zipx"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_DISK_IMAGE:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.bin;*.cue;*.dmg;*.iso;*.toast;*.vcd"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_DEVEL:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.c;*class;*.cpp;*.cs;*.dtd;*.fla;*.java;*.m;*.pl;*.py;*.pas"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_BACKUP:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Name = "*.bak;*tmp"; F.UseName = true; // Vytvorim objekt filtra
                        F.FilterValue_Attr_Directory = ICore.TS_FALSE; F.UseAttributes = true;
                        AddFilter(F); // Zaradim
                        F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                        LogOperator = LOG_OPERATOR_OR;
                    } break;
                case PREDDEFINED_ID_DIR:
                    {
                        INodeFilter F = new INodeFilter(); F.FilterValue_Attr_Directory = ICore.TS_TRUE; F.UseAttributes = true; // Vytvorim objekt filtra
                        AddFilter(F); // Zaradim
                    } break;
            }
        }
    }
}
